package ictbk.ttmk51.grapro.app.safeapplication;

import ictbk.ttmk51.grapro.app.R;
import ictbk.ttmk51.grapro.app.common.Constant;
import ictbk.ttmk51.grapro.app.utils.GetListFile;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class SafeApplication extends Activity implements Constant {
	private File rootFile = new File(sdcardPath);
	private List<String> items = new ArrayList<String>();
	
	private TextView fileName;
	private ImageView fileIcon;
	private CheckBox chk;
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_file_screen);
		
		TextView pathFileName = (TextView) findViewById(R.id.pathFileName);
		pathFileName.setText(sdcardPath);
		
		ListView lv = (ListView) findViewById(R.id.listFile);
		
		Log.i("file name", rootFile.getName());
		
		Log.i("sdcard path", sdcardPath);
		this.items = GetListFile.ReadApplicationFile(rootFile);
		Log.i("So lượng items", String.valueOf(items.size()));
		Log.i("Phần tử thứ nhất", items.get(0));
		final File[] files = new File[items.size()];
		for(int i = 0; i < this.items.size(); i++){
			files[i] = new File(items.get(i));
		}
		
		Log.i("items Size", String.valueOf(items.size()));
		ArrayAdapter<String> fileList = new ArrayAdapter<String>(this, R.layout.file_list, this.items){
			@Override
			public View getView(int position, View v, ViewGroup parent) {
				if(v == null){
					LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
					v = vi.inflate(R.layout.file_list, null);
				}
				if(items !=null){
					chk = (CheckBox)v.findViewById(R.id.imageChoose);
					fileName = (TextView)v.findViewById(R.id.fileName);
					fileIcon = (ImageView)v.findViewById(R.id.fileIcon);
					fileIcon.setBackgroundResource(R.drawable.apk);
					fileName.setText(files[position].getName());
				}
				return v;
			}
		};
		
		lv.setAdapter(fileList);
	}

}
